import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		user: {},
		corpid: ''
	},
	mutations: {
		// 初始化用户信息
		initUser(state) {
			let user = sessionStorage.getItem('user')
			if (user) {
				state.user = JSON.parse(user)
				state.corpid = state.corpid
			}
		},
		// 登录
		login(state, user) {
			// 保存登录状态
			state.user = user;
			state.corpid = user.corpid
			// 存储到本地存储
			sessionStorage.setItem('user', JSON.stringify(state.user));
			sessionStorage.setItem('corpid', state.corpid)
		},
		// 退出登录
		logout(state) {
			// 清除状态
			state.user = {}
			state.corpid = ''
			// 清除本地存储
			sessionStorage.clear()
		}
	},
	actions: {
	},
	modules: {
	}
})
